package 遍历方式;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.function.Consumer;

public class Test {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("堂宝宝");
        list.add("蜘蛛精");
        list.add("至尊宝");

        // 1. for循环
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }

        // 2. 迭代器
        Iterator<String> it = list.iterator();
        while (it.hasNext()) {
            System.out.println(it.next());
        }

        // 3. 增强for循环(foreach遍历)
        for (String s : list) {
            System.out.println(s);
        }
        System.out.println("---------------");
        // 4. JDK 1.8开始之后的Lambda表达式
        list.forEach(System.out::println);
    }
}
